<template>
    <div class="yuan-container container">
       <a-card title="中转库成品库存表">
           <a-tabs type="card" @change="tabChange">
               <a-tab-pane v-for="(item, i) in tabsData" :key="item" :tab="item">
                   <div class="filter-panel">
                       <div class="filter-list" style="float: right;margin-right: 0">
                           <a-button style="margin-right:5px" type="primary" @click="add">新增</a-button>
                           <a-button type="primary" @click="downloadTemplate">下载导入模板</a-button>
                           <a-upload name="file" :multiple="false" :before-upload="beforeUpload" :showUploadList="false">
                               <a-button type="primary" style="margin-left: 5px;margin-right: 0">导入</a-button>
                           </a-upload>
                       </div>
                   </div>
                  <a-table
                      :scroll="{ x: 1500 }"
                      :loading="tableOption.loading"
                      bordered
                      :rowKey="item=>item.id"
                      :data-source="tableOption.dataSource"
                      :columns="tableOption.tableColumns"
                      :pagination="tableOption.pagination">
                  </a-table>
               </a-tab-pane>
           </a-tabs>
       </a-card>
        <!-- 弹窗表单 -->
        <addOrEdit :formData="formData" :tabName="curTab" :visible="formShow" :editId="formEditId" @closeModal="formClose"></addOrEdit>
    </div>
</template>
<script lang="ts">
import {Vue, Component, Watch} from 'vue-property-decorator';
import nextApi from "@/api/nextApi";
import {h, ref} from "vue";
import locale from "ant-design-vue/lib/date-picker/locale/zh_CN";
import tools from "@/utils/tools";
import {UserModule} from "@/store/modules/userModules";
import AddOrEdit from "@/views/reportMgt/transitInventory/components/addOrEdit.vue";
import {downLoadFile} from "@/utils";
@Component({
    components: {AddOrEdit}
})
export default class extends Vue {
    locale = locale;
    tabsData = ["C60","C70","C80","C90"]
    //表格配置
    tableOption: any = {
        loading:false,
        tableColumns: [],
        dataSource: [],
        pagination: {
            pageSize: 10,
            current: 1,
            total: 0,
            showTotal: (total: number) => `共${total}条`,
            onChange: this.pageChange,
        }
    }
    mounted() {
        this.tabChange(this.tabsData[0])
    }
    //监听toggleCollapsed
    @Watch("state")
    stateChange(n){
        if(n){
            this.tableOption.width = 1760
        }else{
            this.tableOption.width = 1640
        }
    }
    //获取vuex中的toggleCollapsed
    get state(){
        return UserModule.toggleCollapsed
    }
    async getTableData(){
        try {
            this.tableOption.loading = true
            let params = {
                pageSize: this.tableOption.pagination.pageSize,
                page: this.tableOption.pagination.current,
                inventoryType: this.curTab

            }
            const res = await nextApi.productStorageList(params)
            this.tableOption.dataSource = res.data?.records || []
            this.tableOption.pagination.total = res.data?.total || 0
            console.log(this.tableOption.dataSource)
        }finally {
            this.tableOption.loading = false
        }

    }
    pageChange(page: number, pageSize: number) {
        this.tableOption.pagination.current = page
        this.getTableData()
    }
    /**
     * @description tab切换
     * **/
    curTab: string = ''
    tabChange(e){
        this.curTab = e
        this.changeColumn()
    }
    changeColumn(){
        switch (this.curTab) {
            case 'C60':
                this.tableOption.tableColumns = [
                    {
                        title: "寄库日期",
                        dataIndex: "storageDate",
                        key: "storageDate",
                        align: "center",
                        width:150,
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.storageDate,
                                        locale: this.locale,
                                        valueFormat: "YYYY-MM-DD",
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.storageDate = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "品名",
                        dataIndex: "materialName",
                        key: "materialName",
                        align: "center",
                    },
                    {
                        title: "备注",
                        dataIndex: "remark",
                        key: "remark",
                        align: "center",
                        width:150,
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.remark,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.remark = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "批号",
                        dataIndex: "batch",
                        key: "batch",
                        align: "center",
                    },
                    {
                        title: "装量/g袋",
                        dataIndex: "loadingQuantity",
                        key: "loadingQuantity",
                        align: "center",
                    },
                    {
                        title: "袋数",
                        dataIndex: "bagNum",
                        key: "bagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.bagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "大袋",
                        dataIndex: "bigBagNum",
                        key: "bigBagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.bigBagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bigBagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "规格",
                        dataIndex: "spec",
                        key: "spec",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.spec,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spec = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "入库数量",
                        dataIndex: "warehousingNum",
                        key: "warehousingNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.warehousingNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.warehousingNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "整件数量",
                        dataIndex: "wholeNum",
                        key: "wholeNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.wholeNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.wholeNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "零件（大包装数量）",
                        dataIndex: "spareBig",
                        key: "spareBig",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.spareBig,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spareBig = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "零件（中包装数量）",
                        dataIndex: "spareMiddle",
                        key: "spareMiddle",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.spareMiddle,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spareMiddle = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "发货",
                        dataIndex: "deliver",
                        key: "deliver",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliver,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliver = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "总库存",
                        dataIndex: "surplus",
                        key: "surplus",
                        align: "center",
                    },
                    {
                        title: "ERP库存",
                        dataIndex: "stockNumErp",
                        key: "stockNumErp",
                        align: "center",
                    },
                    {
                        title: "结存",
                        dataIndex: "stockNumSys",
                        key: "stockNumSys",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.stockNumSys = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "单号",
                        dataIndex: "odd",
                        key: "odd",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.odd,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.odd = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "位置",
                        dataIndex: "position",
                        key: "position",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.position,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.position = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "偏差",
                        dataIndex: "deviation",
                        key: "deviation",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deviation,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deviation = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "08库退",
                        dataIndex: "eightReturn",
                        key: "eightReturn",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.eightReturn,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.eightReturn = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "返工后",
                        dataIndex: "rework",
                        key: "rework",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.rework,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.rework = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "生产日期",
                        dataIndex: "scTime",
                        key: "scTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.scTime,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.scTime = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        align: "center",
                        dataIndex: "action",
                        key: "action",
                        title: "操作",
                        width: 260,
                        customRender: (text: any, record: any) => {
                            const editBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "primary", size: "small" },
                                    on: { click: () => this.edit(record) },
                                },
                                "编辑"
                            );
                            const delBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "danger", size: "small" },
                                    on: { click: () => this.del(record) },
                                },
                                "删除"
                            );
                            const btn: any[] = [];
                            btn.push(editBtn);
                            // btn.push(delBtn);
                            return h("div", btn);
                        },
                    },
                ]
                this.getTableData()
                break;
            case "C70":
                this.tableOption.tableColumns = [
                    {
                        title: "寄库日期",
                        dataIndex: "storageDate",
                        key: "storageDate",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.storageDate,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.storageDate = date
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                    {
                        title: "微检情况",
                        dataIndex: "inspectionStatus",
                        key: "inspectionStatus",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.inspectionStatus,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.inspectionStatus = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "品名",
                        dataIndex: "materialName",
                        key: "materialName",
                        align: "center",
                    },
                    {
                        title: "批号",
                        dataIndex: "batch",
                        key: "batch",
                        align: "center",
                    },
                    {
                        title: "规格",
                        dataIndex: "spec",
                        key: "spec",
                        align: "center",
                    },
                    {
                        title: "袋数",
                        dataIndex: "bagNum",
                        key: "bagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.bagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "发货时间",
                        dataIndex: "deliverTime",
                        key: "deliverTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliverTime,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliverTime = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "发货数量",
                        dataIndex: "deliverNum",
                        key: "deliverNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliverNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliverNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "总库存",
                        dataIndex: "surplus",
                        key: "surplus",
                        align: "center",
                    },
                    {
                        title: "ERP库存",
                        dataIndex: "stockNumErp",
                        key: "stockNumErp",
                        align: "center",
                    },
                    {
                        title: "结存",
                        dataIndex: "stockNumSys",
                        key: "stockNumSys",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.stockNumSys = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "位置",
                        dataIndex: "position",
                        key: "position",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.position,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.position = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "单号",
                        dataIndex: "odd",
                        key: "odd",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.odd,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.odd = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "偏差",
                        dataIndex: "deviation",
                        key: "deviation",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deviation,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deviation = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "08库退",
                        dataIndex: "eightReturn",
                        key: "eightReturn",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.eightReturn,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.eightReturn = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "返工后",
                        dataIndex: "rework",
                        key: "rework",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.rework,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.rework = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "生产日期",
                        dataIndex: "scTime",
                        key: "scTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.scTime,
                                        valueFormat: "YYYY-MM-DD",
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.scTime = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        align: "center",
                        dataIndex: "action",
                        key: "action",
                        title: "操作",
                        width: 260,
                        customRender: (text: any, record: any) => {
                            const editBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "primary", size: "small" },
                                    on: { click: () => this.edit(record) },
                                },
                                "编辑"
                            );
                            const delBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "danger", size: "small" },
                                    on: { click: () => this.del(record) },
                                },
                                "删除"
                            );
                            const btn: any[] = [];
                            btn.push(editBtn);
                            // btn.push(delBtn);
                            return h("div", btn);
                        },
                    },
                ]
                this.getTableData()
                break;
            case "C80":
                this.tableOption.tableColumns = [
                    {
                        title: "寄库日期",
                        dataIndex: "storageDate",
                        key: "storageDate",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.storageDate,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.storageDate = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "品名",
                        dataIndex: "materialName",
                        key: "materialName",
                        align: "center",
                    },
                    {
                        title: "备注",
                        dataIndex: "remark",
                        key: "remark",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.remark,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.remark = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "批号",
                        dataIndex: "batch",
                        key: "batch",
                        align: "center",
                    },
                    {
                        title: "装量/g袋",
                        dataIndex: "loadingQuantity",
                        key: "loadingQuantity",
                        align: "center",
                    },
                    {
                        title: "袋数",
                        dataIndex: "bagNum",
                        key: "bagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.bagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "大袋",
                        dataIndex: "bigBagNum",
                        key: "bigBagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.bigBagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bigBagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "规格",
                        dataIndex: "spec",
                        key: "spec",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.spec,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spec = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "入库数量",
                        dataIndex: "warehousingNum",
                        key: "warehousingNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.warehousingNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.warehousingNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                    {
                        title: "整件数量",
                        dataIndex: "wholeNum",
                        key: "wholeNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.wholeNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.wholeNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "零件（大包装数量）",
                        dataIndex: "spareBig",
                        key: "spareBig",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.spareBig,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spareBig = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "零件（中包装数量）",
                        dataIndex: "spareMiddle",
                        key: "spareMiddle",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.spareMiddle,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.spareMiddle = e.target.value
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                    {
                        title: "发货",
                        dataIndex: "deliver",
                        key: "deliver",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliver,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliver = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "总库存",
                        dataIndex: "surplus",
                        key: "surplus",
                        align: "center",
                    },
                    {
                        title: "ERP库存",
                        dataIndex: "stockNumErp",
                        key: "stockNumErp",
                        align: "center",
                    },
                    {
                        title: "结存",
                        dataIndex: "stockNumSys",
                        key: "stockNumSys",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.stockNumSys = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "单号",
                        dataIndex: "odd",
                        key: "odd",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.odd,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.odd = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "位置",
                        dataIndex: "position",
                        key: "position",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.position,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.position = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "偏差",
                        dataIndex: "deviation",
                        key: "deviation",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deviation,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deviation = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                              }
                            )
                        }
                    },
                    {
                        title: "08库退",
                        dataIndex: "eightReturn",
                        key: "eightReturn",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.eightReturn,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.eightReturn = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "返工后",
                        dataIndex: "rework",
                        key: "rework",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.rework,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.rework = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "生产日期",
                        dataIndex: "scTime",
                        key: "scTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.scTime,
                                        valueFormat: "YYYY-MM-DD",
                                        placeholder: "生产日期",
                                        locale: this.locale,
                                    },
                                    on:{
                                        blur: (date: any) => {
                                            record.scTime = date
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        align: "center",
                        dataIndex: "action",
                        key: "action",
                        title: "操作",
                        width: 260,
                        customRender: (text: any, record: any) => {
                            const editBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "primary", size: "small" },
                                    on: { click: () => this.edit(record) },
                                },
                                "编辑"
                            );
                            const delBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "danger", size: "small" },
                                    on: { click: () => this.del(record) },
                                },
                                "删除"
                            );
                            const btn: any[] = [];
                            btn.push(editBtn);
                            // btn.push(delBtn);
                            return h("div", btn);
                        },
                    },
                ]
                this.getTableData()
                break;
            case "C90":
                this.tableOption.tableColumns = [
                    {
                        title: "寄库日期",
                        dataIndex: "storageDate",
                        key: "storageDate",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.storageDate,
                                        valueFormat: "YYYY-MM-DD",
                                        placeholder: "寄库日期",
                                        locale: this.locale,
                                    },
                                    on:{
                                        blur: (date: any) => {
                                            record.storageDate = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "微检情况",
                        dataIndex: "inspectionStatus",
                        key: "inspectionStatus",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.inspectionStatus,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.inspectionStatus = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "品名",
                        dataIndex: "materialName",
                        key: "materialName",
                        align: "center",
                    },
                    {
                        title: "批号",
                        dataIndex: "batch",
                        key: "batch",
                        align: "center",
                    },
                    {
                        title: "规格",
                        dataIndex: "spec",
                        key: "spec",
                        align: "center",
                    },
                    {
                        title: "袋数",
                        dataIndex: "bagNum",
                        key: "bagNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.bagNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.bagNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "发货时间",
                        dataIndex: "deliverTime",
                        key: "deliverTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliverTime,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliverTime = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "发货数量",
                        dataIndex: "deliverNum",
                        key: "deliverNum",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deliverNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deliverNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "总库存",
                        dataIndex: "surplus",
                        key: "surplus",
                        align: "center",

                    },
                    {
                        title: "ERP库存",
                        dataIndex: "stockNumErp",
                        key: "stockNumErp",
                        align: "center",
                    },
                    {
                        title: "结存",
                        dataIndex: "stockNumSys",
                        key: "stockNumSys",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.stockNumSys = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "位置",
                        dataIndex: "position",
                        key: "position",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.position,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.position = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "入库单号",
                        dataIndex: "odd",
                        key: "odd",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.odd,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.odd = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "偏差",
                        dataIndex: "deviation",
                        key: "deviation",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.deviation,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.deviation = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "08库退",
                        dataIndex: "eightReturn",
                        key: "eightReturn",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.eightReturn,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.eightReturn = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "返工后",
                        dataIndex: "rework",
                        key: "rework",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.rework,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.rework = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "生产日期",
                        dataIndex: "scTime",
                        key: "scTime",
                        align: "center",
                        customRender:(text:string,record:any,index:number)=>{
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.scTime,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                        placeholder: "生产日期",
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.scTime = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        align: "center",
                        dataIndex: "action",
                        key: "action",
                        title: "操作",
                        width: 260,
                        customRender: (text: any, record: any) => {
                            const editBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "primary", size: "small" },
                                    on: { click: () => this.edit(record) },
                                },
                                "编辑"
                            );
                            const delBtn = h(
                                "a-button",
                                {
                                    style: { marginRight: "5px" },
                                    props: { icon: "edit", type: "danger", size: "small" },
                                    on: { click: () => this.del(record) },
                                },
                                "删除"
                            );
                            const btn: any[] = [];
                            btn.push(editBtn);
                            // btn.push(delBtn);
                            return h("div", btn);
                        },
                    },
                ]
                this.getTableData()
                break;
            default:
                this.tableOption.tableColumns = []
                this.tableOption.tableData = []
        }
        this.tableOption.tableColumns.forEach(item=>{
            item.width = 150
            if (item.title == '操作')item.fixed = 'right'
        })
        this.tableOption.tableColumns[this.tableOption.tableColumns.length-1].width = 220
    }
    formShow = false
    add(){
        this.formShow = true
    }
    formData: any = {}
    formEditId = ''
    edit(record: any){
        this.formShow = true
        this.formEditId = record.id
        this.formData = record
    }
    async updateByTable(record:any){
        this.tableOption.loading = true
        const result = await nextApi.productStorageUpdateProd(record)
        this.$message.success(result.msg)
        await this.getTableData()
        this.tableOption.loading = false
    }
    del(record: any){
    }
    formClose(){
        this.formShow = false
        this.tabChange(this.curTab)
        this.formEditId = ''
    }
    downloadTemplate(){
        this.tableOption.loading = true
        nextApi.getProductStorageImportTemplate(this.curTab,'配方颗粒',(res: any) => {
            const blob = new Blob([res.data], {
                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                // type: "application/vnd.ms-excel",
            });
            downLoadFile(blob, this.curTab +"库存表导入模板");
            this.tableOption.loading = false;
        });
    }
    beforeUpload(file: any) {
        let formData = new FormData();
        formData.append("file", file);
        formData.append("inventoryType",this.curTab)
        this.uploadTemplate(formData);
        return false;
    }
    async uploadTemplate(formData: any) {
        this.tableOption.loading = true;
        try {
            const res = await nextApi.importProductStorage(formData);
            this.$message.success(res.msg);
            await this.getTableData()
        } finally {
            this.tableOption.loading = false;
        }
    }
}
</script>
<style scoped lang="scss">
</style>
